home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / sat / msat09.tgz / BLOGDISP.C < prev    next >
Text File  |  1994-09-17  |  5KB  |  209 lines

  1. /*
  2.         Display program for BL files, which record broadcast server activity.
  3.         This code is not particularly portable. It was written for Microsoft C under DOS.
  4.         It will also compile under Quick C for windows, and the unixtime module sorts
  5.         out the problem that ANSI standard time is not the same as good old unix time.
  6.  
  7.         fFixed -     This flag is FALSE for early UoSAT-3 and UoSAT-5 BL files because there was
  8.                           a bug in the onboard logging task wich caused incorrect counts in the
  9.                           entries for overwritten requests and un-fresh requests.
  10.  
  11.         Original: Jeff Ward, Surrey Satellite Technology, Ltd.
  12. */
  13. /*
  14.         History:
  15.         19 April 1993
  16.         Added ability to read the version from the log file if the first entry
  17.         in the log file has length 2. Otherwise version is assumed to be
  18.         version 1.
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <time.h>
  24. #include <ctype.h>
  25.  
  26. #include "viewlog.h"
  27. #include "blogdisp.h"
  28.  
  29. #define MAGIC 25569.0
  30.  
  31. char writebuf[200];
  32.  
  33. struct STAT_STRUCT stats;
  34. int fBytemode = FALSE;                                                    /* Display byte counts */
  35. int fCmdmode = FALSE;                                                        /* Display command counts */
  36. int fDirmode = FALSE;                                                        /* Display dir counts */
  37. int first = TRUE;
  38.  
  39. int blogdisp(FILE *pFile)
  40. {
  41.     short len;
  42.     short version;
  43.     int i;
  44.  
  45.     if ((version = GetVer(pFile)) == 0)
  46.         return(1);
  47.  
  48.     for (i = 0; i < 3; i++)
  49.     {
  50.         switch (i)
  51.         {
  52.             case 0:
  53.                 fBytemode = TRUE;
  54.                 fCmdmode  = FALSE;
  55.                 fDirmode  = FALSE;
  56.                 break;
  57.             case 1:
  58.                 fBytemode = FALSE;
  59.                 fCmdmode  = TRUE;
  60.                 fDirmode  = FALSE;
  61.                 break;
  62.             default:
  63.                 fBytemode = FALSE;
  64.                 fCmdmode  = FALSE;
  65.                 fDirmode  = TRUE;
  66.                 break;
  67.         }
  68.  
  69.         first = TRUE;
  70.     
  71.         fseek(pFile, 0L, SEEK_SET);
  72.  
  73.         GetVer(pFile);
  74.  
  75.         while (!feof(pFile))
  76.         {
  77.             if (fread(&len, sizeof(short), 1, pFile)) 
  78.                 if (fread(&stats, len, 1, pFile))
  79.                     process(&stats, version);
  80.         }
  81.  
  82.         writetext("\n");
  83.     }
  84.  
  85.     return(0);
  86. }
  87.  
  88. short GetVer(FILE * pFile)
  89. {
  90.     short ver = -1;
  91.     short len;
  92.  
  93.     if (fread(&len, sizeof(short), 1, pFile))
  94.     {
  95.         if (len == 2)
  96.         {
  97.             fread(&ver, 2, 1, pFile);
  98.         }
  99.         else
  100.         {
  101.             ver = 1;
  102.             fseek(pFile, 0L, SEEK_SET);
  103.         }
  104.     }
  105.  
  106.     return ver;
  107. }
  108.  
  109. /*------------------------------------------------*/
  110. /* Display whichever values the user wanted to      */
  111. /* display, as indicated by display flags.      */
  112. /*------------------------------------------------*/
  113.  
  114. int process(struct STAT_STRUCT *pStats, short version)
  115. {
  116.     struct tm *ptm;
  117.     long residue;
  118.  
  119.     ptm = gmtime(&pStats->LogTime);
  120.  
  121.     if (first)
  122.     {
  123.         sprintf(writebuf, "Broadcast activity %02d/%02d/%02d - ", ptm->tm_mday, ptm->tm_mon+1, ptm->tm_year);
  124.         writetext(writebuf);
  125.  
  126.         if (fCmdmode)
  127.             writetext("(Commands)\n\n");
  128.         else if (fBytemode)
  129.             writetext("(Bytes)\n\n");
  130.         else if (fDirmode)
  131.             writetext("(Directories)\n\n");
  132.  
  133.         if (fBytemode)
  134.         {
  135.             writetext("HH:MM    Req'd     Tx'd     OvrWr   TooOld    Ended    Fopen   PFHerr      EOF\n");
  136.         }
  137.         else if (fCmdmode)
  138.         {
  139.             writetext("HH:MM Start  Fill   End  Long  NO-1  NO-2  NO-3  Stations\n");
  140.         }
  141.         else if (fDirmode)
  142.         {
  143.             writetext("HH:MM Requests  Bytes Tx'd\n");
  144.         }
  145.  
  146.         first = FALSE;
  147.     }
  148.  
  149.     sprintf(writebuf, "%02d:%02d ", ptm->tm_hour, ptm->tm_min);
  150.     writetext(writebuf);
  151.  
  152.     if (fCmdmode)
  153.     {
  154.         sprintf(writebuf, "% 5ld ", pStats->nStartFile);
  155.         writetext(writebuf);
  156.         sprintf(writebuf, "% 5ld ", pStats->nHolefills);
  157.         writetext(writebuf);
  158.         sprintf(writebuf, "% 5ld ", pStats->nEndFile);
  159.         writetext(writebuf);
  160.         sprintf(writebuf, "% 5d ", pStats->nLongFile);
  161.         writetext(writebuf);
  162.         sprintf(writebuf, "% 5ld ", pStats->nNoFile);
  163.         writetext(writebuf);
  164.         sprintf(writebuf, "% 5ld ", pStats->nNoRoom);
  165.         writetext(writebuf);
  166.         sprintf(writebuf, "% 5ld ", pStats->nNotOK);
  167.         writetext(writebuf);
  168.         sprintf(writebuf, "% 5d", pStats->nNewStns);
  169.         writetext(writebuf);
  170.     }
  171.     else if (fBytemode)
  172.     {
  173.         sprintf(writebuf, "%8ld ", pStats->nbRequested);
  174.         writetext(writebuf);
  175.         sprintf(writebuf, "%8ld ", pStats->nbTransmitted);
  176.         writetext(writebuf);
  177.         sprintf(writebuf, "%9lu ", pStats->nbOverwrite);
  178.         writetext(writebuf);
  179.         sprintf(writebuf, "%8ld ", pStats->nbUnfresh);
  180.         writetext(writebuf);
  181.         sprintf(writebuf, "%8ld ", pStats->nbEnd);
  182.         writetext(writebuf);
  183.         sprintf(writebuf, "%8ld ", pStats->nbFopenErr);
  184.         writetext(writebuf);
  185.         sprintf(writebuf, "%8ld ", pStats->nbPfhErr);
  186.         writetext(writebuf);
  187.         sprintf(writebuf, "%8ld ", pStats->nbEof);
  188.         writetext(writebuf);
  189.         residue = pStats->nbRequested - (pStats->nbTransmitted +
  190.                             pStats->nbOverwrite + pStats->nbUnfresh +
  191.                             pStats->nbEnd + pStats->nbFopenErr + pStats->nbPfhErr +
  192.                             pStats->nbEof);
  193.         sprintf(writebuf, " (%7ld)", residue);
  194.         writetext(writebuf);
  195.     }
  196.     else if (fDirmode)
  197.     {
  198.         sprintf(writebuf, "   %5ld    ", pStats->nDirReqs);
  199.         writetext(writebuf);
  200.         sprintf(writebuf, "%8ld", pStats->nbDirTxd);
  201.         writetext(writebuf);
  202.     }
  203.  
  204.     writetext("\n");
  205.  
  206.     return 1;
  207. }
  208.  
  209.